package com.rabbitmq.rabbitmqextensions.config;

import com.rabbitmq.rabbitmqextensions.constant.Constants;
import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 延迟
 */
@Configuration
public class DelayConfig {

    @Bean("delayQueue")
    public Queue delayQueue() {
        return QueueBuilder.durable(Constants.DELAY_QUEUE).build();
    }

    /**
     * 延迟交换机
     * @return
     */
    @Bean("delayExchange")
    public DirectExchange delayExchange() {
        return ExchangeBuilder.directExchange(Constants.DELAY_EXCHANGE).delayed().build();
    }

    @Bean("delayBind")
    public Binding delayBind(@Qualifier("delayExchange") DirectExchange directExchange,
                             @Qualifier("delayQueue") Queue queue) {
        return BindingBuilder.bind(queue).to(directExchange).with(Constants.DELAY_ROUTINGKEY);
    }
}
